package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Feedback extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	Connection conn;
	Statement st;
	String db="jdbc:mysql://localhost:3306/hirel";
	ResultSet rs;
	   
     public Feedback() {
    	try {
    	Class.forName("com.mysql.jdbc.Driver");	
     
        conn=DriverManager.getConnection(db,"root","root");
        System.out.println("connection success");
    	}
    	catch(Exception e)
    	{
    		e.printStackTrace();
    	}
    }
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

			HttpSession session=request.getSession();
		String userName=(String) session.getAttribute("userName");
		String message=request.getParameter("message");
		System.out.println(userName);
		System.out.println(message);
try {
			
			st=conn.createStatement();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String query=  "insert	into feedback(userName, message) values('"+userName+"','"+message+"')";
		System.out.println(query);
		try {
		
        st.execute(query);
		 
		}
		catch (Exception e) {
		 e.printStackTrace();
		}
		
		response.sendRedirect("SuccessfulFeedback.jsp");
		
		
	}

	

}
